

package cn.edu.swu.miniwebsvr.core;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Parameter {
    private String method;
    private String url;
    private Map<String, String> urlParams = new HashMap<>();
    private Map<String, String> bodyParams = new HashMap<>();
    private Map<String, String> headers = new HashMap<>();

    // TODO: [222024321072054/李欣雨]  补充必要的构造函数、setter、getter方法

    public Parameter() { }

    public void setMethod(String method) { this.method = method; }
    public String getMethod() { return this.method; }

    public void setUrl(String url) { this.url = url; }
    public String getUrl() { return this.url; }

    public Map<String, String> getUrlParams()  { return urlParams; }
    public Map<String, String> getBodyParams() { return bodyParams; }
    public Map<String, String> getHeaders()    { return headers; }

    public Map<String, String> getAllParams() {
        Map<String, String> allParams = new HashMap<>();
        allParams.putAll(urlParams);
        allParams.putAll(bodyParams);
        return Collections.unmodifiableMap(allParams);
    }

    public String getParam(String name) {
        if (bodyParams.containsKey(name)) {
            return bodyParams.get(name);
        }
        return urlParams.get(name);
    }
}